define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'xeditor'], function ($, undefined, Backend, Table, Form) {
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'merchant/mtyx_aqsc_org/index',
                    multi_url: 'merchant/mtyx_aqsc_org/multi',
                    table: 'mtyx_aqsc_org_source',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('ID'), sortable: true},
                        {field: 'province', title: '身份', operate: 'LIKE'},
                        {field: 'county', title: '县域', operate: 'LIKE'},
                        {field: 'certificate', title: '证书', operate: 'LIKE'},

                        {field: 'product_name', title: '产品名称', operate: 'LIKE'},
                        {field: 'certified_unit', title: '获证单位', operate: 'LIKE'},
                        {field: 'production_scale', title: '生产规模', operate: 'LIKE'},
                        {field: 'period_of_validity', title: '有效期', operate: 'LIKE'},
                        {field: 'main_units', title: '主要生产经营单位', operate: 'LIKE'},
                        {field: 'ewm', title: '二维码地址', operate: 'LIKE'},

                        {field: 'createtime', title: '创建时间', events: Table.api.formatter.datetime,operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'updatetime', title: '更新时间', events: Table.api.formatter.updatetime,operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});